<?php
/**
 * 
 * 
 * @version $Id: Route.php 677 2013-02-19 13:57:06Z linsir123 $
 */
class Route 
{
	/**
	 * 商品
	 */
	static function urlItem($params)
	{
		$r = 'item/'. $params['iid'] .'/'. Helper::itemAttach($params['iid']);
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 商品(跳转)
	 */
	static function urlItemJump($params)
	{
		if (isset($params['iid']))	
			$r = 'item/jump/iid/'. $params['iid'];
		elseif (isset($params['url'])) 
			$r = 'goto/tb/'. base64_encode($params['url']);
			
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 商店
	 */
	static function urlShop($params)
	{
		$nick = empty($params['nick'])?0:$params['nick'];
		$sellerId = empty($params['seller_id'])?0:$params['seller_id'];
		
		///
		$r = sprintf("shop/%s-%s",
			urlencode($nick), $sellerId);
			
		return lpUrl::__($r);
	}
	
	/**
	 * 商店(跳转)
	 */
	static function urlShopJump($params)
	{
		if (isset($params['nick']))	
			$r = 'shop/jump/nick/'. urlencode($params['nick']);
		elseif (isset($params['url'])) 
			$r = 'goto/tb/'. base64_encode($params['url']);
			
		///
		return lpUrl::__($r);
	}
	
	/**
	 * 分类(普通)
	 * 
	 * @example /list/pinyin-cid/pinyin-keyword/sort-p
	 */
	static function urlClass($params)
	{
		static $_init = false;
		if ( ! $_init) {
			$_init = true;
			App::V('pinyin');
		}
		
		///
		$pinyin = empty($params['pinyin'])?0:$params['pinyin'];
		$cId = empty($params['cid'])?0:$params['cid'];
		
		$emptyKeyword = empty($params['empty_keyword'])?0:$params['empty_keyword'];
		$pinyinKeyword = empty($params['pinyin_keyword'])?0:$params['pinyin_keyword'];
		$keyword = empty($params['keyword'])?0:$params['keyword'];
		
		$sort = empty($params['sort'])?0:$params['sort'];
		$p = empty($params['p'])?0:$params['p'];
		
		///
		if (empty($pinyin)) {
			$class = M::classes()->get($cId);
			if ( ! empty($class)) 
				$pinyin = $class['pinyin'];
			else 
				$pinyin = $cId = 0;
		}
		
		///
		if ( ! empty($keyword) && empty($pinyinKeyword)) {
			$pinyinKeyword = string2pinyin($keyword);
			if ($emptyKeyword) 
				$keyword = 0;
		}
		
		///
		$r = sprintf("list/%s-%s/%s-%s/%s-%s",
			$pinyin, $cId, 
			$pinyinKeyword, urlencode($keyword),
			$sort, $p);
			
		return lpUrl::__($r);
	}
	
	/**
	 * 分类(折扣)
	 * 
	 * @example /zhe/pinyin-keyword/sort-p
	 */
	static function urlZhe($params)
	{
		static $_init = false;
		if ( ! $_init) {
			$_init = true;
			App::V('pinyin');
		}
		
		///
		$emptyKeyword = empty($params['empty_keyword'])?0:$params['empty_keyword'];
		$pinyinKeyword = empty($params['pinyin_keyword'])?0:$params['pinyin_keyword'];
		$keyword = empty($params['keyword'])?0:$params['keyword'];
		
		$sort = empty($params['sort'])?0:$params['sort'];
		$p = empty($params['p'])?0:$params['p'];
		
		///
		if ( ! empty($keyword) && empty($pinyinKeyword)) {
			$pinyinKeyword = string2pinyin($keyword);
			if ($emptyKeyword) 
				$keyword = 0;
		}
		
		///
		$r = sprintf("zhe/%s-%s/%s-%s",
			$pinyinKeyword, urlencode($keyword),
			$sort, $p);
			
		return lpUrl::__($r);
	}
	
	/**
	 * 
	 * 
	 * @example /list/pinyin-cid/pinyin-keyword/sort-p
	 */
	static function urlShops($params)
	{
		static $_init = false;
		if ( ! $_init) {
			$_init = true;
			App::V('pinyin');
		}
		
		///
		$pinyin = empty($params['pinyin'])?0:$params['pinyin'];
		$cId = empty($params['cid'])?0:$params['cid'];
		
		$emptyKeyword = empty($params['empty_keyword'])?0:$params['empty_keyword'];
		$pinyinKeyword = empty($params['pinyin_keyword'])?0:$params['pinyin_keyword'];
		$keyword = empty($params['keyword'])?0:$params['keyword'];
		
		$sort = empty($params['sort'])?0:$params['sort'];
		$p = empty($params['p'])?0:$params['p'];
		
		///
		if ( ! empty($keyword) && empty($pinyinKeyword)) {
			$pinyinKeyword = string2pinyin($keyword);
			if ($emptyKeyword) 
				$keyword = 0;
		}
		
		///
		$r = sprintf("shops/%s-%s/%s-%s/%s-%s",
			$pinyin, $cId, 
			$pinyinKeyword, urlencode($keyword),
			$sort, $p);
			
		return lpUrl::__($r);
	}
	
	/**
	 * 
	 */
	static function urlPhoto($params)
	{
		return base64_encode($params['url']);
	}
}
